/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Control;

import Control.Processor;
import DAO.UsuarioDAO;
import Model.Usuario;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import javax.servlet.ServletException;

/**
 *
 * @author 0433101
 */
public class validaCadastro extends Processor {

    @Override
    public void execute() throws ServletException, IOException {
        PrintWriter out = getResponse().getWriter();
        String login = getRequest().getParameter("login");
        
        try {
            Usuario user = UsuarioDAO.pesquisarByLogin(login);
            
            if(user == null){
                out.println("<font color='green'> Usuário válido! </font>");
            }
            else{
                out.println("<font color='red'> Usuário já existe! </font>");
            }
        } catch (SQLException ex) {
            throw new ServletException("Database error!");
        } catch (ClassNotFoundException ex) {
            throw new ServletException("System error!");
        }
    }
    
}
